﻿using System.Data;
using BO.Infrastructure.StaticData;
using ChannelVN.Cached.Base;

namespace GUI.Controls.Sport
{
    public partial class OtherNewsInDetailPage : ControlBase
    {
        #region Overrides of ControlBase

        public override string CacheConfigName
        {
            get { return "Controls-Sport-OtherNewsInDetailPage"; }
        }

        public override bool IsCachedChanged(long newsId, string zoneId, long tagId)
        {
            return newsId > 0 || !string.IsNullOrEmpty(zoneId);
        }

        #endregion
        private const string LiFormat = @"<li><span></span><a title=""{0}"" href=""{2}"">{1}</a></li>";

        public bool DataBind(DataTable dt)
        {

            if (dt != null && dt.Rows.Count > 0)
            {
                var sb = new System.Text.StringBuilder("<ul>");
                for (var i = 0; i < dt.Rows.Count; i++)
                {
                    var r = dt.Rows[i];
                    if (i == dt.Rows.Count / 2) sb.Append("</ul><ul class=\"mgl10 fl\">");
                    sb.Append(string.Format(
                            LiFormat,
                            r[SqlConstants.NewsPublish.EncodedTitle],
                            r[SqlConstants.NewsPublish.Title],
                            r[SqlConstants.NewsPublish.Url]
                        ));
                }
                sb.Append("</ul>");
                ltrList.Text = sb.ToString();
                return true;
            }

            return false;
        }
    }
}